/*********************************************************************
 * ObjectPoolSample.java created on Feb 2, 2010
 *
 * This file is part of Sure Tech Support Portal System. 
 * Copyright @ 2010 Sure Tech (HK) Limited. All rights reserved.
 * Sure Tech PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *********************************************************************/
package com.bizdigger.db;

import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.impl.StackObjectPool;

/**
 * @Author: Mac Wang
 * @Date: Feb 2, 2010 2:01:59 PM 
 * @Email: mac@suretech.com.hk
 */

public class ObjectPoolSample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Object obj = null;
		PoolableObjectFactory factory = new PoolableObjectFactorySample();
		ObjectPool pool = new StackObjectPool(factory);
		
		try
		{
			for(int i = 0; i< 100; i++)
			{
				System.out.println("==" + i + "==");
				obj = pool.borrowObject();
				System.out.println("borrow object:" + obj);
				pool.returnObject(obj);
			}
			obj = null;
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if(obj != null)
					pool.returnObject(obj);
				pool.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}

}
